<?php
namespace App\Http\Controllers\H5;

use App\Service\H5\StaffService;
use Illuminate\Http\Request;

class LoginController extends BaseController
{
    //登录
    public function dologin(Request $request)
    {
        $uname = $request->post('uname', '');
        $upwd = $request->post('passwd', '');
        $res = StaffService::dologin($uname, $upwd);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //过期
    public function guoqi(Request $request)
    {
        $logtime = $request->post('logtime', 0);
        if ($logtime < date('Ymd', time())) {
            return self::toJson(1, '登录已过期');
        }
        return self::toJson();
    }

    //获取权限
    public function bomMenu(Request $request)
    {
        $uid = $request->post('uid', 0);
        $role_id = $request->post('role_id', 0);
        $res = StaffService::bomMenu($uid, $role_id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //工作台菜单
    public function wsMenu(Request $request)
    {
        $uid = $request->post('uid', 0);
        $role_id = $request->post('role_id', 0);
        $res = StaffService::workspace($uid, $role_id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

//    //过期设置
//    public function configSet(Request $request)
//    {
//        $item = $request->post('item', '');
//        $period = $request->post('period', '');
//        $config = file_get_contents('config.json');
//        $res = json_decode($config, true);
//        if (!$res) {
//            return self::toJson(-2, '没有配置');
//        }
//        if ($item) {
//            $res['item_name'] = $item;
//        }
//        if ($period) {
//            $res['period'] = date('YmdHis', strtotime($period));
//        }
//        file_put_contents('config.json', json_encode($res, 384));
//        return self::toJson();
//    }
}